#include <stdio.h>
#include <elf.h>

int main(int argc, char *argv[])
{
    int *p = (int *)argv;
    int i;
    Elf32_auxv_t *aux;

    printf("=== argument count: %d\n", *(p - 1));
    for (i = 0; i < *(p - 1); i++) {
        printf("argument[%d]: %s\n", i, (char *)(*(p + i)));
    }

    p += i;
    p++;    // 跳过参数列表后面的0(空字符串)

    printf("=== environment:\n");
    while (*p != 0) {
        printf("%s\n", (char *)(*p));
        p++;
    }
    p++;    // 跳过环境变量列表后面的0(空字符串)

    printf("=== dynamic linker auxiliary vectors:\n");
    aux = (Elf32_auxv_t *)p;
    while (aux->a_type != AT_NULL) {
        printf("type: %02d, value: %#x\n", aux->a_type, aux->a_un.a_val);
        aux++;
    }

    return 0;
}
